package com.example.combwyaq.http;



import android.util.Log;

import com.example.combwyaq.interceptor.SignInterceptor;
import com.example.combwyaq.interceptor.TokenInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public final class TokenSignRetrofit implements HttpImpl {
    private static final String TAG = "yqs";

    private TokenSignRetrofit() {
        Log.i(TAG, "TokenSignRetrofit: ");
    }

    private static Retrofit retrofit;

    @Override
    public Retrofit getRetrofit() {
        Log.i(TAG, "getRetrofit: ");
        return retrofit;
    }



    public static class Build {


        public Build() {
            Log.i(TAG, "Build: ");
            create();
        }

        private void create() {
            Log.i(TAG, "create: ");
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
            okBuilder.addInterceptor(new TokenInterceptor());
            okBuilder.addInterceptor(new SignInterceptor());
            okBuilder.addInterceptor(interceptor);
            okBuilder.connectTimeout(30 * 1000, TimeUnit.MILLISECONDS);
            okBuilder.writeTimeout(30 * 1000, TimeUnit.MILLISECONDS);
            okBuilder.readTimeout(30 * 1000, TimeUnit.MILLISECONDS);
            Retrofit.Builder builder = new Retrofit.Builder();
            builder.client(okBuilder.build());
            builder.baseUrl(Api.BaseUrl);
            builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());
            builder.addConverterFactory(GsonConverterFactory.create());
            retrofit = builder.build();
        }

        public TokenSignRetrofit build() {
            Log.i(TAG, "build: ");
            return new TokenSignRetrofit();
        }

    }


}
